import request from '../utils/request.js'
import apiConfig from '../config/api.js'
import { articleApi } from './article.js'
import { sightApi } from './sight.js'
import { ticketApi } from './ticket.js'
import { commentApi } from './comment.js'
import { orderApi } from './order.js'
import { carouselApi } from './carousel.js'



// 用户相关接口
export const userApi = {
	// 用户登录
	login: (data) => {
		return request({
			url: apiConfig.apiList.login,
			method: 'POST',
			data: data
		})
	},
	// 用户注册
	register: (data) => {
		return request({
			url: apiConfig.apiList.register,
			method: 'POST',
			data: data
		})
	},
	
	// 获取用户列表
	getUsers: () => {
		return request({
			url: apiConfig.apiList.getUsers,
			method: 'GET'
		})
	},
	
	// 添加用户
	addUser: (data) => {
		return request({
			url: apiConfig.apiList.addUser,
			method: 'POST',
			data: data
		})
	},
	
	// 删除用户
	deleteUser: (id) => {
		return request({
			url: `${apiConfig.apiList.deleteUser}/${id}`,
			method: 'DELETE'
		})
	},
	
	// 更新用户
	updateUser: (id, data) => {
		return request({
			url: `${apiConfig.apiList.updateUser}/${id}`,
			method: 'PUT',
			data: data
		})
	},
	
	// 根据名字模糊查询用户
	searchUserByName: (username) => {
		return request({
			url: `${apiConfig.apiList.searchUserByName}/${username}`,
			method: 'GET'
		})
	},
	
	// 根据角色查询用户
	getUsersByRole: (role) => {
		return request({
			url: `${apiConfig.apiList.getUsersByRole}/${role}`,
			method: 'GET'
		})
	},
	
	// 根据状态查询用户
	getUsersByStatus: (status) => {
		return request({
			url: `${apiConfig.apiList.getUsersByStatus}/${status}`,
			method: 'GET'
		})
	},
	
	// 用户表分页
	getUsersPage: (page, size, filters = {}) => {
		return request({
			url: `${apiConfig.apiList.getUsersPage}/${page}/${size}`,
			method: 'GET',
			data: filters
		})
	},
	
	// 用户总数
	getUsersTotal: () => {
		return request({
			url: apiConfig.apiList.getUsersTotal,
			method: 'GET'
		})
	},
	
	// 最新注册的用户
	getNewUsers: () => {
		return request({
			url: apiConfig.apiList.getNewUsers,
			method: 'GET'
		})
	},
	
	// 获取个人信息
	getUserInfo: () => {
		return request({
			url: apiConfig.apiList.getUserInfo,
			method: 'GET',
			needAuth: true
		})
	},
	
	// 更新个人信息
	updateProfile: (data) => {
		return request({
			url: apiConfig.apiList.updateProfile,
			method: 'PUT',
			data: data,
			needAuth: true
		})
	}
}

// 导出所有API
export {
	articleApi,
	sightApi,
	ticketApi,
	commentApi,
	orderApi,
	carouselApi
}


